/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：SingleTouchHandler.java <br>
 * 创建时间：2013-5-19 下午8:26:32 <br>
 * 所属项目：GmudEX <br>
 * @author 12548 <br>
 */
package lostland.gmud.exv2.blgframework.impl;

import android.view.MotionEvent;
import android.view.View;


/**
 * 类名：SingleTouchHandler <br>
 * 说明：
 *
 * @author 12548
 */
public class SingleTouchHandler implements TouchHandler {
	boolean isTouched;
	public static int touchX;
	public static int touchY;
	public static int t2x, t2y;


//	public static volatile int flag = 0;

	public static int oriX, oriY;


	float scaleX;
	float scaleY;
	float s2x, s2y;

	public SingleTouchHandler(View view, float scaleX, float scaleY, float sc2x, float sc2y) {
		view.setOnTouchListener(this);
		//view.setOnTouchListener(new GmudTouchHandler());

		this.scaleX = scaleX;
		this.scaleY = scaleY;

		s2x = sc2x;
		s2y = sc2y;
	}

	/* （非 Javadoc）
	 * @see android.view.View.OnTouchListener#onTouch(android.view.View, android.view.MotionEvent)
	 */
	@Override
	public boolean onTouch(View v, MotionEvent event) {
		synchronized (this) {
//			TouchEvent touchEvent = touchEventPool.newObject();
			switch (event.getAction()) {
				case MotionEvent.ACTION_DOWN:
//				touchEvent.type=TouchEvent.TOUCH_DOWN;
					isTouched = true;
					break;
				case MotionEvent.ACTION_MOVE:
//				touchEvent.type=TouchEvent.TOUCH_DRAGGED;
					isTouched = true;
					break;
				case MotionEvent.ACTION_CANCEL:
				case MotionEvent.ACTION_UP:
//				touchEvent.type= TouchEvent.TOUCH_UP;
					isTouched = false;
					break;
			}

			oriX = (int) event.getX();
			oriY = (int) event.getY();

//			touchEvent.x = (int)(event.getX()*scaleX * BLGFastRenderView.multiplier);
//			touchEvent.y = (int)(event.getY()*scaleY * BLGFastRenderView.multiplier);
			touchX = (int) (event.getX() * scaleX * BLGFastRenderView.multiplier);
			touchY = (int) (event.getY() * scaleY * BLGFastRenderView.multiplier);


			t2x = (int) (oriX * BLGGame.s2x);
			t2y = (int) (oriY * BLGGame.s2y);

//			touchEventsBuffer.add(touchEvent);

			return true;
		}
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.blgframework.impl.TouchHandler#isTouchDown(int)
	 */
	@Override
	public boolean isTouchDown(int pointer) {
		synchronized (this) {
			if (pointer == 0)
				return isTouched;
			else
				return false;
		}
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.blgframework.impl.TouchHandler#getTouchX(int)
	 */
	@Override
	public int getTouchX(int pointer) {
		synchronized (this) {
			return touchX;
		}
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.blgframework.impl.TouchHandler#getTouchY(int)
	 */
	@Override
	public int getTouchY(int pointer) {
		synchronized (this) {
			return touchY;
		}
	}

//	/* （非 Javadoc）
//	 * @see lostland.gmud.exv2.blgframework.impl.TouchHandler#getTouchEvents()
//	 */
//	@Override
//	public List<TouchEvent> getTouchEvents() {
//		synchronized(this)
//		{
//			int len=touchEvents.size();
//			for(int i=0;i<len;i++)
//				touchEventPool.free(touchEvents.get(i));
//			touchEvents.clear();
//			touchEvents.addAll(touchEventsBuffer);
//			touchEventsBuffer.clear();
//			return touchEvents;
//		}
//	}
}
